package com.dibang.app.operation.view.impl;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dibang.app.R;
import com.dibang.app.bean.PeerItem;
import com.dibang.app.mvp.abs.AbsView;
import com.dibang.app.mvp.util.DateUtils;
import com.dibang.app.operation.control.abs.TripListControl;
import com.dibang.app.operation.model.abs.TripListModel;
import com.dibang.app.operation.presenter.abs.TripListPresenter;
import com.dibang.app.operation.view.abs.TripListView;
import com.dibang.app.ui.GroupMessageActivity;
import com.dibang.app.view.PeerTitleHtmlHandler;
import com.dibang.app.view.ViewHelper;

import java.util.Calendar;

/**
 * Created by wxl on 2019/8/12.
 */
public class TripListViewImpl extends AbsView<TripListControl, TripListView, TripListPresenter, TripListModel> implements TripListView {


    @Override
    public void setTripListViewLinearManagerByData(@NonNull RecyclerView listView) {
        ViewHelper.setRecyclerViewLinearLayoutManager(listView);
        BaseQuickAdapter adapter;
        listView.setAdapter(adapter = new BaseQuickAdapter<PeerItem, BaseViewHolder>(R.layout.item_peer_layout, PeerItem.get()) {
            @Override
            protected void convert(BaseViewHolder helper, PeerItem item) {
                helper.setText(R.id.item_peer_start_view,item.start);
                helper.setText(R.id.item_peer_end_view,item.end);
                helper.setText(R.id.item_peer_status_btn_view,"查看");
                helper.setText(R.id.item_peer_user_name_view,item.name);
                int position = helper.getAdapterPosition();
                helper.setText(R.id.item_peer_status_1_text_view,position%5==0?"进行中":"已结束");
                helper.setTextColor(R.id.item_peer_status_1_text_view,ViewHelper.getResColor(listView.getContext(),position%5==0?R.color.xui_config_color_red:R.color.gray_text_color));
                PeerTitleHtmlHandler.onBindPeerTitleHtmlContent(item,helper.getView(R.id.item_peer_user_title_view));
                Calendar rightNow = Calendar.getInstance();
                rightNow.setTimeInMillis(System.currentTimeMillis());
                String day = (rightNow.get(Calendar.MONTH)+1)+"月"+rightNow.get(Calendar.DAY_OF_MONTH)+"日";
                helper.setText(R.id.item_peer_user_day_view,day);
            }

        });

        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                view.getContext().startActivity(new Intent(view.getContext(), GroupMessageActivity.class));
            }
        });
    }
}
